1042A - Benches - CodeForces Solution


binary search implementation *1100

Please click on ads to support us..

Python Code:

from math import ceil
n = int(input()); ap = int(input())
l = [*(int(input()) for i in range(n))]
m = max(l)
s = [*(m-x for x in l)]
sums = sum(s); ap1 = max(ap-sums,0)
mik = max(m,m+ceil(ap1/n))
print(mik,m+ap)

C++ Code:

#include <bits/stdc++.h> 
using namespace std;
using i64 = long long;
const int N = (int)(2e5 + 10);
i64 t[4 * N];
//i64 a[N];
i64 ans = LONG_MIN;
i64 p[N];
vector<i64> sz(N) ;

void solve() { 
	int n, m;
	cin >> n >> m;

	vector<int> vi(n);
	int mx = -1;
	for (int i = 0; i < n; i++) {
	    cin >> vi[i];
	    mx = max(mx, vi[i]);
	} 

	int resMax = mx + m;
	for (int i = 0; i < m; i++) {
		sort(vi.begin(), vi.end());
		vi[0] += 1;	
	} 

	int resMin = INT_MIN;
	for (int i = 0; i < n; i++) {
		resMin = max(resMin, vi[i]);
	} 



	
	cout << resMin << " " << resMax;



}                                                                            	
  
                                                                                                             	
int main() {                                                      
	std::ios::sync_with_stdio(false); 
	std::cin.tie(nullptr);           
   	// freopen("A.in", "r", stdin); 
   	// freopen("A.out", "w", stdout);
	int t = 1;
	
	while (t--) solve();
                                                                      
}                      	                   


Comments

Submit
0 Comments
More Questions

221A - Little Elephant and Function
492C - Vanya and Exams
1369B - AccurateLee
892B - Wrath
999A - Mishka and Contest
727C - Guess the Array
1625C - Road Optimization
1715D - 2+ doors
267A - Subtractions
1582A - Luntik and Concerts
560A - Currency System in Geraldion
946A - Partition
1068B - LCM
1692E - Binary Deque
679A - Bear and Prime 100
488A - Giga Tower
14A - Letter
1150A - Stock Arbitraging
1552A - Subsequence Permutation
1131F - Asya And Kittens
1475F - Unusual Matrix
133B - Unary
1547A - Shortest Path with Obstacle
624A - Save Luke
1238A - Prime Subtraction
1107C - Brutality
1391B - Fix You
988B - Substrings Sort
312A - Whose sentence is it
513A - Game